package com.study.common.utils;

/**
 * @author yaojinshan
 * @version 1.0
 * @description: TODO
 * @date 2019/5/30 10:51
 */
public class RequestUtil {
    public static String isNull(String str) {
        if (str == null) {
            return "";
        }
        return str.trim();
    }
    /**
     * 普通
     */
    private static String[] denied_all = { "drop", "select", "declare",
            "insert", "update", "delete", "cast", "alert", "create", "where",
            "join", "iframe", "alter", "\"", "like", "%22", "'", "%27",
            "script", "confirm", "modify", "</", "%3b", "rename", "%3c", "%3e",
            "unicode", ";", "<", "grant", ">", };
    /**
     * 关键字过滤判断
     *<pre> </pre>
     * @param text
     * @return
     */
    public static boolean isDeniedAll(String text){
        return isDenied(text, denied_all);
    }

    /**
     * 是否存在需要过滤的字符
     * @param text
     * @return 存在返回true
     */
    public static boolean isDenied(String text,String[] denied){
        text = isNull(text).toLowerCase();//增加过滤器判断条件, 参数转化成小写, 再判断,
        for(int j=0;j<denied.length;j++){
            String denied_Text = isNull(denied[j]);
            if(text.indexOf(denied_Text)>-1){
                System.out.println(denied_Text);
                return true;
            }
        }
        return false;
    }
    public static String paraToFirst(String[] para) {
        if(para==null){
            return "";
        }else if (para instanceof String[]){
            if(para.length>0){
                return para[0];
            }else{
                return "";
            }
        }else{
            return "";
        }
    }
}
